/*
 * @Author: your name
 * @Date: 2021-06-08 20:17:02
 * @LastEditTime: 2022-03-07 20:48:14
 * @LastEditors: xuesong
 * @Description: In User Settings Edit
 * @FilePath: \BLE-SDK-SVN499-V09\projects\ble_peripheral\uart_ble\src\Remote\user_prcess.h
 */
#ifndef __USER_PRCESS_H__
#define __USER_PRCESS_H__


#include "bcomdef.h"
#include "ll_def.h"
#include "comdef.h"
#include "User_keyScan.h"
#include "halPeripheral.h"

#ifdef __cplusplus
extern "C"
{
#endif

typedef enum
{
    P12_SYNC_CMD  = 0xC5,
    P12_SYNC_EVENT = 0xC6,
    P12_SYNC_NOTIFY = 0xC7,
} P12_SYNC_HEAD;

typedef enum
{
    P12_EVENT_SUCCESS  = 0x10,
    P12_EVENT_paramErr = 0x11,
    P12_EVENT_RunErr   = 0x12,
    P12_EVENT_CheckErr = 0x13,
    P12_EVENT_NotSupport = 0x14,
} P12_EVENT_Result;


typedef enum
{
    P12_CMD_Sleep           = 0x20,     //休眠指令
    P12_CMD_AskBleStatus    = 0x21,     //查询蓝牙状态
    P12_CMD_SetAdvInterval  = 0x22,     //设置广播间隔
    P12_CMD_SetConnectParam = 0x23,     //设置连接参数
    P12_CMD_SetMaufactAdv   = 0x24,     //设置厂商广播内容
    P12_CMD_SetAllAdv       = 0x25,     //设置所有广播内容
    P12_CMD_ContralAdv      = 0x26,     //开启或关闭广播
    P12_CMD_SetScanRSP      = 0x27,     //设置ScanRSP数据包内容
    P12_CMD_SetRFDB         = 0x28,     //设置发射功率
    P12_CMD_DisconnectBle   = 0x29,     //断开蓝牙连接
    P12_CMD_SetBleName      = 0x2A,     //设置蓝牙名称
    P12_CMD_SetBleMac       = 0x2B,     //设置蓝牙mac地址
    P12_CMD_RestBle         = 0x2C,     //复位蓝牙
    P12_CMD_SetSoftFIFO     = 0x2D,     //设置软件流控
    P12_CMD_AskNotity       = 0x2E,     //请求Notify    
    P12_CMD_SetAdvType      = 0x2F,     //设置广播类型
    P12_CMD_SetCharaterData = 0x30,     //发送特征值数据给手机，并更新对应的特征值
    P12_CMD_ReadCharaterData = 0x31,    //读取特征值的数据
    P12_CMD_WriteCharaterData = 0x32,   //写特征值数据，但是不会将该数据发送给手机  
    P12_CMD_ReadBleMac       = 0x38,     //读取当前设备的蓝牙地址  


    P12_CMD_SetLedData      = 0x50,     //设置显示数据
    P12_CMD_PAIRRomte       = 0x51,     //进入配对模式
    P12_CMD_GetRomteMac     = 0x52,     //获取遥控MAC地址
    P12_CMD_QuitOrSave      = 0x53,     //退出并保存
    P12_CMD_BzOnOff         = 0x54,     //蜂鸣器状态
    P12_CMD_ECOMode         = 0x55      //省电模式
} P12_CMD;

typedef enum
{
    P12_Notify_Poweron      = 0x10,     //蓝牙上电通知
    P12_Notify_DisConnect   = 0x11,     //蓝牙断开连接通知
    P12_Notify_Connect      = 0x12,     //蓝牙连接成功通知
    P12_Notify_Data2Mcu     = 0x13,     //手机下传数据通知
    P12_Notify_NotifyEn     = 0x14,     //Notification 或 indicate 使能或关闭通知
    P12_Notify_Character    = 0x15,     //Characteristic Read Request 通知
    P12_Notify_IO_Weakup    = 0x16,     //io 唤醒蓝牙通知
    P12_Notify_Resve1       = 0x17,     //保留
    P12_Notify_IndicateOK   = 0x18,     //Indication 属性特征值数据接收成功通知
    P12_Notify_Resve2       = 0x19,     //保留
    P12_Notify_OverTmSleep  = 0x1A,      //蓝牙空闲超时自动Sleep通知
    P12_Notify_KeyStatus    = 0x1B      //Key Status
} P12_Notity_CMD;

typedef enum
{
    P12_DisConnet_TMOUT     = 0x00,     //通信超时断开
    P12_CenterDisConnect    = 0x01,     //手机主动断开
    P12_PeripheralDisConnect = 0x02,     //设备主动断开
} P12_Disconnect_reson;

typedef struct
{
	uint8_t	 Head;
	uint8_t  Length;
    uint8_t  cmd;
	uint8_t  data[32];
} bleuart_p12cmd_t;

typedef struct
{
	uint8_t	 Head;
	uint8_t  Length;
    uint8_t  event;
    uint8_t  cmd;
	uint8_t  data[32];
} bleuart_p12event_t;

/*********************************************************************
 * MACROS
 */
extern uint16_t UartSetCharaterHandle;
typedef union {
    struct
    {
        unsigned char on		        : 1;    // 
        unsigned char WeakMcu           : 1;    // 
        unsigned char miroDisplay       : 1;    // 
        unsigned char Pairing	        : 1;    // 
        unsigned char EcoEn		        : 1;    // 
        unsigned char GetBzS		    : 1;    // 
    }flagBit;
    uint8_t flagByte;
}UserFlag_t;
extern UserFlag_t UserFlag;
//--------------------------------------------------
typedef enum{
    D_USER_PROCESS_ON   = 0,
    D_USER_PROCESS_PUMPING,
    D_USER_PROCESS_Charg,
    D_USER_PROCESS_Lo,
    D_USER_PROCESS_IDLE,
}USER_PROCESS;
//----------------------------------------------------
typedef union {
    struct
    {
        unsigned char _16ms		        : 1;    // 
        unsigned char _32ms		        : 1;    // 
        unsigned char _64ms		        : 1;    // 
        unsigned char _128ms		    : 1;    // 
        unsigned char _256ms	        : 1;    // 
        unsigned char HalfSecond        : 1;    // 
        unsigned char Second            : 1;    // 
        unsigned char _2Second          : 1;    // 
    }flagBit;
    uint8_t flagByte;
}ClockFlag_t;
//-----------------------------------------------------
#define     ENable_BAT_LO           1
typedef struct{
	union {
        struct
        {
            unsigned char run 		        : 1;    // 
            unsigned char Subrun 	        : 1;    // 
            unsigned char idle   	        : 1;    // 
            unsigned char WeakUp 	        : 1;    // 
            unsigned char PowerON 	        : 1;    // 
            unsigned char DisplayFlash 	    : 1;    //  0.5s flash Display
            unsigned char FBDisplayFlash1S 	: 1;    //  Forbid flash 1s
            unsigned char ChargeFull        : 1;    //  chargeFull
            unsigned char RestKeyIn	        : 1;    //  
            unsigned char BleStatus         : 1;    //  
            unsigned char BackLight         : 1;    //  
            unsigned char ReciveBle         : 1;    //  
            unsigned char UserCalib         : 1;    //  
            unsigned char handleOFF         : 1;    // 手动关机  
        }flagBit;
        uint16_t flagByte;
    }ProcessFlag;
    ClockFlag_t clockflag;
    uint8 process;
    uint8 subProcess;
    uint8_t subProcessHalfSec;
    uint32_t ProcessHalfSec;
}User_Process_t;
extern User_Process_t UserProcess;
/*********************************************************************
 * FUNCTIONS
 */
void SwitchUserSubProcess(uint8 process);
void SwitchUserSubProcessNext(void);
void SwitchUseProcess(USER_PROCESS process);
uint16  UartBuff_unProcessByte(uart_data_t uartData);
void Buff2UartStructdata(uart_data_t *Structdata,const uint8_t *data,uint16_t len);
void ble_rec_pro(void);
void FunUserProcess(void);
#ifdef __cplusplus
}
#endif

#endif
